package myschool.service;

import myschool.dao.GradeDao;
import myschool.entity.Grade;
import myschool.entity.Page;
import myschool.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class GradeService {
    public static final GradeService ME=new GradeService();

    public static final Logger Log = LoggerFactory.getLogger(GradeService.class);


    public Page<Grade> page(int pageNo, int pageSize) {
        SqlSession session = MybatisUtil.get();
        try {
            GradeDao dao = session.getMapper(GradeDao.class);
            List<Grade> list = dao.find(pageNo, pageSize);
            int total=dao.findTotal();
            return new Page<>(list,pageNo,total,pageSize);
        } finally {
            MybatisUtil.close(session);
        }
    }

    public Grade get(Long id) {
        SqlSession session = MybatisUtil.get();
        try {
            GradeDao dao = session.getMapper(GradeDao.class);
            return dao.get(id);
        } finally {
            MybatisUtil.close(session);
        }
    }

    public List<Grade> findAll() {
        SqlSession session = MybatisUtil.get();
        try {
            GradeDao dao = session.getMapper(GradeDao.class);
            return dao.findAll();
        } finally {
            MybatisUtil.close(session);
        }
    }

}
